home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / msdos / editors / eedraw / src / eep / eelayer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-29  |  3.3 KB  |  186 lines

  1. /* Set up the basic primitives for Layer control */
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include "\usr\include\intr_lib.h"
  6. #include "program.h"
  7. #include "eelayer.h"
  8.  
  9.  
  10. #define MAX_LAYERS 44
  11. #define LAYER_OFF 0
  12. #define LAYER_ON  1
  13. #define LAYER_ENABLED 2
  14. #define LAYER_UNUSED  4
  15.  
  16. #define BLACK        0
  17. #define RED        4
  18. #define GREEN        2
  19. #define BLUE        1
  20. #define YELLOW        14
  21. #define CYAN        3
  22. #define MAGENTA        5
  23. #define WHITE        15
  24.  
  25.  
  26. static char *UsedLayers[] ={
  27.     "Wire",
  28.     "Bus",
  29.     "Gate",
  30.     "IEEE",
  31.     "PinFun",
  32.     "PinNum",
  33.     "PinNam",
  34.     "RefDes",
  35.     "Attr",
  36.     "Device",
  37.     "Notes",
  38.     "NetNam",
  39.     "Pin",
  40.     "END"
  41. };
  42. static int LayerInfo[] ={
  43.      WHITE,0x8200,
  44.      YELLOW,0x0100,
  45.      CYAN,0x0100,
  46.      RED,0x0100, 
  47.      BLUE,0x0100, 
  48.      YELLOW,0x0100, 
  49.      BLUE,0x0100, 
  50.      YELLOW,0x0100, 
  51.      YELLOW,0x0100, 
  52.      CYAN,0x0100, 
  53.      BLUE,0x0100, 
  54.      RED,0x0100,
  55.      WHITE,0x0100
  56. };
  57.  
  58. LayerStruct *Layer;     /* define basic layer data pointer */
  59.  
  60. void SeedLayers()
  61.  
  62. {
  63.     int pt;
  64.     
  65.     Layer = (LayerStruct *) MyMalloc(sizeof(LayerStruct));
  66.     
  67.     
  68.     pt=0;
  69.     Layer->CurrentWidth = 1;
  70. /* seed Up the Layer Strings and colours, set all user layers off */
  71.     while((strcmp(UsedLayers[pt],"END"))!=0){
  72.         /* set layer name up */
  73.      
  74.         strcpy(Layer->LayerNames[pt],UsedLayers[pt]);
  75.         Layer->LayerStatus[pt]=
  76.              (LayerInfo[(pt * 2) +1] & 0x0f00)/0x100;
  77.  
  78.         Layer->LayerColor[pt] = LayerInfo[(pt * 2)];
  79.  
  80.         if(LayerInfo[(pt * 2) +1] & 0x8200)
  81.             Layer->CurrentLayer=pt;
  82.      
  83.         pt++;
  84.     }
  85.      
  86.     Layer->NumberOfLayers=pt-1;
  87.     while(pt!=MAX_LAYERS){
  88.         sprintf(Layer->LayerNames[pt],"User%d",pt);
  89.  
  90.         
  91.         Layer->LayerStatus[pt] = LAYER_UNUSED;
  92.                             /* layers clear */
  93.                             /* and Off */
  94.         Layer->LayerColor[pt] = INTR_COLOR_BLACK;
  95.         /* Colours Black */ 
  96.         pt++;
  97.     }
  98.     
  99.  
  100.      
  101. }
  102. int ReturnCurrentWidth()
  103. {
  104.     return(Layer -> CurrentWidth);
  105. }
  106. void SetCurrentWidth(int Width)
  107. {
  108.     Layer -> CurrentWidth = Width;
  109. }
  110. int ReturnCurrentLayer()
  111. {
  112.     return(Layer -> CurrentLayer);
  113. }
  114. void SetCurrentLayer(int layer)
  115. {
  116.     Layer->CurrentLayer = layer;
  117. }
  118. char *ReturnLayerName(layer)
  119. int layer;
  120. {
  121.     return(Layer->LayerNames[layer]);
  122. }
  123. void SetLayerName(layer,Name)
  124. int layer;
  125. char *Name;
  126. {
  127.     strcpy(Layer->LayerNames[layer],Name);
  128. }
  129. int ReturnLayerMode(layer)
  130. int layer;
  131. {
  132.     return(Layer->LayerStatus[layer]);
  133. }
  134. void SetLayerMode(layer,Mode)
  135. int layer,Mode;
  136. {
  137.     Layer->LayerStatus[layer]=Mode;
  138. }
  139.  
  140. int ReturnLayerColor(layer)
  141. int layer;
  142. {
  143.     return(Layer->LayerColor[layer]);
  144.      
  145. }
  146. void SetLayerColor(layer,Color)
  147. int layer,Color;
  148. {
  149.     Layer->LayerColor[layer]=Color;
  150. }
  151. int ReturnLayerNumber()
  152. {
  153.     return(Layer->NumberOfLayers);
  154. }
  155. void SetLayerNumber(Number)
  156. int Number;
  157. {
  158.     Layer->NumberOfLayers=Number;
  159. }
  160. void LoadLayers(f)
  161. FILE *f;    /* Load the Layer Structuer from a file */
  162. {
  163.     int cnt,Number;
  164.     char Line[LINE_LEN];
  165.     int Mode,Color,layer;
  166.     char Name[0x10];
  167.  
  168.     fgets(Line,LINE_LEN-1,f);    /* read line */
  169.     sscanf(Line,"%s %d %d",Name,&Number,&Layer->CurrentLayer);
  170.     if((strcmp(Name,"EELAYER"))!=0){
  171.         /* Error! */
  172.     } else
  173.         SetLayerNumber(Number);
  174.     cnt=0;
  175.     while(cnt!=Number+1){
  176.         fgets(Line,LINE_LEN-1,f);    /* read line */
  177.         sscanf(Line,"%s %d %d %d",Name,&Color,&Mode,&layer);
  178.         SetLayerName(layer,Name);
  179.         SetLayerColor(layer,Color);
  180.         SetLayerMode(layer,Mode);
  181.         cnt++;
  182.     }
  183.     fgets(Line,LINE_LEN-1,f);    /* read trailing Line */
  184.  
  185. }
  186.